package com.sky.client;

import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;

@FeignClient(name = "sky-service-order")
public interface OrderClient {

    /**
     * 用户下单
     *
     * @param ordersSubmitDTO
     * @return
     */
    @PostMapping("/user/order/submit")
    Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO);

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/user/order/payment")
    Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception;

    /**
     * 历史订单查询
     *
     * @param page
     * @param pageSize
     * @param status   订单状态 1待付款 2待接单 3已接单 4派送中 5已完成 6已取消
     * @return
     */
    @GetMapping("/user/order/historyOrders")
    Result<PageResult> page(@RequestParam int page, @RequestParam int pageSize, @RequestParam(required = false) Integer status);

    /**
     * 查询订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/user/order/orderDetail/{id}")
    Result<OrderVO> details(@PathVariable("id") Long id);

    /**
     * 用户取消订单
     *
     * @param id
     * @return
     */
    @PutMapping("/user/order/cancel/{id}")
    Result cancel(@PathVariable("id") Long id) throws Exception;

    /**
     * 再来一单
     *
     * @param id
     * @return
     */
    @PostMapping("/user/order/repetition/{id}")
    Result repetition(@PathVariable Long id);

    /**
     * 用户催单
     *
     * @param id
     * @return
     */
    @GetMapping("/user/order/reminder/{id}")
    Result reminder(@PathVariable("id") Long id);

    /**
     * 订单搜索
     *
     * @param page
     * @param pageSize
     * @param number
     * @param phone
     * @param status
     * @param beginTime
     * @param endTime
     * @param userId
     * @return
     */
    @GetMapping("/admin/order/conditionSearch")
    Result<PageResult> conditionSearch(
            @RequestParam(required = false, defaultValue = "1") int page,
            @RequestParam(required = false, defaultValue = "10") int pageSize,
            @RequestParam(required = false) String number,
            @RequestParam(required = false) String phone,
            @RequestParam(required = false) Integer status,
            @RequestParam(required = false) LocalDateTime beginTime,
            @RequestParam(required = false) LocalDateTime endTime,
            @RequestParam(required = false) Long userId
    );

    /**
     * 各个状态的订单数量统计
     *
     * @return
     */
    @GetMapping("/admin/order/statistics")
    Result<OrderStatisticsVO> statistics();

    /**
     * 订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/admin/order/details/{id}")
    Result<OrderVO> adminDetails(@PathVariable("id") Long id);

    /**
     * 接单
     *
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/admin/order/confirm")
    Result confirm(@RequestBody OrdersConfirmDTO ordersConfirmDTO);

    /**
     * 拒单
     *
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/admin/order/rejection")
    Result rejection(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception;

    /**
     * 取消订单
     *
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/admin/order/cancel")
    Result adminCancel(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception;

    /**
     * 派送订单
     *
     * @param id
     * @return
     */
    @PutMapping("/admin/order/delivery/{id}")
    Result delivery(@PathVariable("id") Long id);

    /**
     * 完成订单
     *
     * @param id
     * @return
     */
    @PutMapping("/admin/order/complete/{id}")
    Result complete(@PathVariable("id") Long id);
    
    /**
     * 支付成功回调处理
     * @param outTradeNo
     */
    @PutMapping("/order/paySuccess")
    void paySuccess(@RequestParam String outTradeNo);
    
    /**
     * 根据状态和下单时间查询订单
     * @param status
     * @param time
     * @return
     */
    @GetMapping("/order/getByStatusAndOrdertimeLT")
    List<Orders> getByStatusAndOrdertimeLT(@RequestParam Integer status, @RequestParam LocalDateTime time);
    
    /**
     * 更新订单信息
     * @param orders
     */
    @PutMapping("/order/update")
    void update(@RequestBody Orders orders);
    
    /**
     * 根据状态和时间范围统计订单数量
     * @param map
     * @return
     */
    @PostMapping("/order/countByMap")
    Integer countByMap(@RequestBody Map map);
    
    /**
     * 根据时间范围查询营业额
     * @param map
     * @return
     */
    @PostMapping("/order/sumByMap")
    Double sumByMap(@RequestBody Map map);
    
    /**
     * 查询商品销量排名
     * @param beginTime
     * @param endTime
     * @return
     */
    @GetMapping("/order/getSalesTop10")
    List<GoodsSalesDTO> getSalesTop10(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime beginTime, 
                                      @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime);
}